var {
  clickContent,
  randomUtils,
  existContent,
  fmtUtils,
  logUtils,
  clickUtils,
} = require("../../utils/index");
var { Action } = require("../../base/index");
var ad = require("../../ads/touTiao/index");

var aTreasure = new Action("开宝箱", {});
aTreasure.exec = function () {
  var content = "开宝箱得金币";
  if (clickContent(content)) {
    sleep(randomUtils.getRandom(2, 3, 1000));
    var content = "看视频再领";
    var result = existContent(content);

    if (result) {
      var text = result.type == 0 ? result.result.text() : result.result.text;
      logUtils.info(text + "/" + fmtUtils.getNumber(text));
      if (result.type == 0) {
        clickUtils.clickTextUI(result.result);
      } else {
        clickUtils.clickTextOCR(result.result);
      }
      sleep(randomUtils.getRandom(2, 3, 1000));
      ad.startWatchAd(20);
    }
  }
};

module.exports = aTreasure;
